<?php
class UserModel extends Model {
	function get_user_name($id)   //根据用户id获取用户名
	{
		$l=M();
		$list=$l->query("SELECT user_name FROM user where user_id={$id}");
		return $list[0][user_name];
	}
        function get_user_id($name)   //根据用户name获取用户id
	{
		$l=M();
		$list=$l->query("SELECT user_id FROM user where user_name='{$name}'");
		return $list[0]['user_id'];
	}
	function get_user()   //获取用户列表
	{
		$l=M();
		$list=$l->query("SELECT user_name,user_id FROM user");
		return $list;
	}
        function get_admin($user_name)  //通过用户名获取权限
        {
            $l=M();
            $list=$l->query("SELECT admin FROM user where user_name='{$user_name}'");
            return $list[0]['admin'];
        }
        function add_richeng($rc_date,$rc_time,$rc_body,$user_id,$gk)   //保存新添加的日程
        {
            $sql="INSERT INTO richeng (rc_date,rc_time,rc_body,user_id,gk) "
            ."VALUES ({$rc_date},'{$rc_time}','{$rc_body}',{$user_id},{$gk})";
            $list=$this->execute($sql);
            return $list;
        }

        
        function check_user_pwd($user_name,$user_pwd)  //检测原始密码是否正确  $user_name    $user_pwd
        {
            $l=M();
            $list=$l->query("SELECT user_pwd FROM user where user_name='{$user_name}'");
            if(count($list)>0){
                if($list['0']['user_pwd']==$user_pwd)
                {   //原始密码正确
                    return 1;
                }
                 else
                 {  //原始密码不正确
                    return 2;
                 }
            }
            else
            {   //系统错误
                return 3;
            }
        }
        //保存更改的密码，$user_name 为用户名，$user_pwd为md5加密的新密码
        function save_change_pwd($user_name,$user_pwd)
        {
            $l=M();
            $list=$l->execute("UPDATE user SET user_pwd='{$user_pwd}' WHERE user_name='{$user_name}'");
            if($list)
                //密码修改成功返回1
                return 1;
            else
            //系统错误返回3
                return 3;
        }

        
}
?>